﻿'*******************************************************************
' Program: Data Center Visio Rack Tool
' Author: Albert E Edlund
' Date:
'
' Purpose:
'
'
' INSERT into tblattrGeoData (geoSpatial) 
' VALUES (geography::STGeomFromText('POINT(-87.62778997421264 41.882023079055145)', 4326))
'
' INSERT into tblattrGeoData (geoSpatial) 
' VALUES (geography::STGeomFromText('POINT(-88.14794540405273 41.77140769972487)', 4326))
'
' INSERT into tblNetworkLink (linkSpatial) 
' VALUES (geography::STGeomFromText('LINESTRING(-88.14828872680664 41.77079957087898, -87.62774705886841 41.88167161294157)', 4326))

'
'*******************************************************************

Imports Microsoft.Practices.EnterpriseLibrary.Common
Imports Microsoft.Practices.EnterpriseLibrary.Data
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling
Imports Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging

Imports System
Imports System.ComponentModel
Imports System.Collections.Generic

Imports Microsoft.SqlServer.Types
Imports System.Collections.ObjectModel

Imports System.IO
Imports System.Xml
Imports System.Collections
Imports System.Data

Imports System.Runtime.InteropServices
Imports Microsoft.Office.Interop.Visio


Imports visRackLocations
Imports visRackLocations.clsDC_RackData
Imports visRackLocations.clsDC_RackData.rackURRI
Imports visRackLocations.dc_Port




Public Class clsNetworkLinks


#Region " Properties and definitions "

    Public m_db As Database
    Public m_ds As DataSet
    Public m_dt As DataTable

    Public m_tempds As DataSet
    Public m_tempdt As DataTable

    Public m_dc As dc_Link
    Public m_oc As Collection(Of dc_Link)

    Private strUserId As String

    Private _clsVisio As visRackLocations.clsVisioSupport

    Private m_deleteCommand As DbCommand
    Private m_insertCommand As DbCommand
    Private m_updateCommand As DbCommand

    Public Const readAll As String = "selecttblNetworkLink"

    ' who am I
    Private myEnum As DC_RackTables = DC_RackTables.tblNetworkLink

    '********* visio snippet vb.net vis0041vb ******************
    Private _drawingApplication As Microsoft.Office.Interop.Visio.Application
    Public Property drawingApplication() As Microsoft.Office.Interop.Visio.Application
        Get
            Return Me._drawingApplication
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Application)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("ApplicationValueIsNull", _
                    "drawingApplication is Null.")
            End If
            Me._drawingApplication = value
        End Set
    End Property

    '********* visio snippet vb.net vis0043vb ******************
    Private _drawingDocument As Microsoft.Office.Interop.Visio.Document
    Public Property drawingDocument() As Microsoft.Office.Interop.Visio.Document
        Get
            Return Me._drawingDocument
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Document)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("DocumentValueIsNull", _
                    "drawingDocument is Null.")
            End If
            Me._drawingDocument = value
        End Set
    End Property

    '********* visio snippet vb.net vis0045vb ******************
    Private _drawingWindow As Microsoft.Office.Interop.Visio.Window
    Public Property drawingWindow() As Microsoft.Office.Interop.Visio.Window
        Get
            Return Me._drawingWindow
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Window)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("WindowValueIsNull", _
                    "drawingWindow is Null.")
            End If
            Me._drawingWindow = value
        End Set
    End Property

    '********* visio snippet vb.net vis0044vb ******************
    Private _drawingPage As Microsoft.Office.Interop.Visio.Page
    Public Property drawingPage() As Microsoft.Office.Interop.Visio.Page
        Get
            Return Me._drawingPage
        End Get
        Set(ByVal value As Microsoft.Office.Interop.Visio.Page)
            If (value Is Nothing) Then
                Throw New System.ArgumentNullException("PageValueIsNull", _
                    "drawingPage is Null.")
            End If
            Me._drawingPage = value
        End Set
    End Property

    Public m_customstencilpath As String = My.Settings.path_custom_stencils
    Public Property _CustomStencilPath() As String
        Get
            Return Me.m_customstencilpath
        End Get
        Set(ByVal value As String)
            Me.m_customstencilpath = value
        End Set
    End Property



#End Region

#Region " Move/Transform Data "
    '
    ' create columns
    '
    Public Sub CreateTableColumns(ByRef tempTable As DataTable)

        Dim newDC As dc_Link = New dc_Link(strUserId)

        Try
            Dim colLinkKey As New System.Data.DataColumn
            colLinkKey.ColumnName = "linkKey"
            colLinkKey.DataType = GetType(Integer)
            colLinkKey.DefaultValue = m_dc.LinkKey
            tempTable.Columns.Add(colLinkKey)

            Dim collinkCableLabel As New System.Data.DataColumn
            collinkCableLabel.ColumnName = "linkCableLabel"
            collinkCableLabel.DataType = GetType(String)
            collinkCableLabel.DefaultValue = m_dc.linkCableLabel
            tempTable.Columns.Add(collinkCableLabel)

            Dim collinkPortAKey As New System.Data.DataColumn
            collinkPortAKey.ColumnName = "linkPortAKey"
            collinkPortAKey.DataType = GetType(Integer)
            collinkPortAKey.DefaultValue = m_dc.linkPortAKey
            tempTable.Columns.Add(collinkPortAKey)

            Dim collinkPortBKey As New System.Data.DataColumn
            collinkPortBKey.ColumnName = "linkPortBKey"
            collinkPortBKey.DataType = GetType(Integer)
            collinkPortBKey.DefaultValue = m_dc.linkPortBKey
            tempTable.Columns.Add(collinkPortBKey)

            Dim collinkType As New System.Data.DataColumn
            collinkType.ColumnName = "linkType"
            collinkType.DataType = GetType(dc_Link.enumLinkTypes)
            collinkType.DefaultValue = m_dc.linkType
            tempTable.Columns.Add(collinkType)

            Dim collinkMediaLength As New System.Data.DataColumn
            collinkMediaLength.ColumnName = "linkMediaLength"
            collinkMediaLength.DataType = GetType(Integer)
            collinkMediaLength.DefaultValue = m_dc.linkMediaLength
            tempTable.Columns.Add(collinkMediaLength)

            Dim collinkSpatial As New System.Data.DataColumn
            collinkSpatial.ColumnName = "linkSpatial"
            collinkSpatial.DataType = GetType(Microsoft.SqlServer.Types.SqlGeography)
            collinkSpatial.DefaultValue = Nothing
            tempTable.Columns.Add(collinkSpatial)

            Dim collinktxtSpatial As New System.Data.DataColumn
            collinktxtSpatial.ColumnName = "linktxtSpatial"
            collinktxtSpatial.DataType = GetType(String)
            collinktxtSpatial.DefaultValue = Nothing
            tempTable.Columns.Add(collinktxtSpatial)

            Dim collinkSpeed As New System.Data.DataColumn
            collinkSpeed.ColumnName = "linkSpeed"
            collinkSpeed.DataType = GetType(Integer)
            collinkSpeed.DefaultValue = m_dc.linkSpeed
            tempTable.Columns.Add(collinkSpeed)

            Dim collinkLatency As New System.Data.DataColumn
            collinkLatency.ColumnName = "linkLatency"
            collinkLatency.DataType = GetType(Double)
            collinkLatency.DefaultValue = m_dc.linkLatency
            tempTable.Columns.Add(collinkLatency)

            Dim collinkPLState As New System.Data.DataColumn
            collinkPLState.ColumnName = "linkPLState"
            collinkPLState.DataType = GetType(dc_Link.enumLinkState)
            collinkPLState.DefaultValue = m_dc.linkPLState
            tempTable.Columns.Add(collinkPLState)

            Dim collinkComments As New System.Data.DataColumn
            collinkComments.ColumnName = "linkComments"
            collinkComments.DataType = GetType(String)
            collinkComments.DefaultValue = m_dc.linkComments
            tempTable.Columns.Add(collinkComments)

            Dim collinkLastUpdate As New System.Data.DataColumn
            collinkLastUpdate.ColumnName = "linkLastUpdate"
            collinkLastUpdate.DataType = GetType(Date)
            collinkLastUpdate.DefaultValue = m_dc.linkLastUpdate
            tempTable.Columns.Add(collinkLastUpdate)

            Dim collinkLastEdit As New System.Data.DataColumn
            collinkLastEdit.ColumnName = "linkLastEdit"
            collinkLastEdit.DataType = GetType(String)
            collinkLastEdit.DefaultValue = m_dc.linkLastEdit
            tempTable.Columns.Add(collinkLastEdit)

            newDC = Nothing

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        If newDC IsNot Nothing Then
            newDC = Nothing
        End If


    End Sub

    '
    ' use this initially for adding rows
    '
    Public Sub movePropertiesToDataRow _
                (ByRef tempRow As DataRow, _
                 ByVal tempDC As dc_Link)

        Try

            With tempDC
                tempRow.SetField("linkKey", .LinkKey)
                tempRow.SetField("linkCableLabel", .linkCableLabel)
                tempRow.SetField("linkPortAKey", .linkPortAKey)
                tempRow.SetField("linkPortBKey", .linkPortBKey)
                tempRow.SetField("linkType", .linkType)
                tempRow.SetField("linkMediaLength", .linkMediaLength)
                tempRow.SetField("linktxtSpatial", .linktxtSpatial)
                tempRow.SetField("linkSpatial", .linkSpatial)
                tempRow.SetField("linkSpeed", .linkSpeed)
                tempRow.SetField("linkLatency", .linkLatency)
                tempRow.SetField("linkPLState", .linkPLState)
                tempRow.SetField("linkComments", .linkComments)
                tempRow.SetField("linkLastUpdate", .linkLastUpdate)
                tempRow.SetField("linkLastEdit", strUserId)
            End With



        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Sub moveDataRowToProperties _
        (ByVal tempRow As DataRow)

        Try
            m_dc.initProperties()
            m_dc.linkLastEdit = strUserId
            With tempRow
                m_dc.LinkKey = .Item("linkKey")

                If Not (IsDBNull(.Item("linkCableLabel"))) Then
                    m_dc.linkCableLabel = .Item("linkCableLabel")
                End If

                m_dc.linkPortAKey = .Item("linkPortAKey")
                m_dc.linkPortBKey = .Item("linkPortBKey")

                If Not (IsDBNull(.Item("linkType"))) Then
                    m_dc.linkType = .Item("linkType")
                End If

                m_dc.linkMediaLength = .Item("linkMediaLength")

                If Not (IsDBNull(.Item("linktxtSpatial"))) Then
                    m_dc.linktxtSpatial = .Item("linktxtSpatial")
                Else
                    m_dc.linktxtSpatial = ""
                End If
                If Not (IsDBNull(.Item("linkSpatial"))) Then
                    m_dc.linkSpatial = .Item("linkSpatial")
                Else
                    m_dc.linkSpatial = Nothing
                End If

                m_dc.linkSpeed = .Item("linkSpeed")
                m_dc.linkLatency = .Item("linkLatency")
                m_dc.linkPLState = .Item("linkPLState")

                If Not (IsDBNull(.Item("linkComments"))) Then
                    m_dc.linkComments = .Item("linkComments")
                End If

                If Not (IsDBNull(.Item("linkLastUpdate"))) Then
                    m_dc.linkLastUpdate = .Item("linkLastUpdate")
                End If
                If Not (IsDBNull(.Item("linklastedit"))) Then
                    m_dc.linkLastEdit = .Item("linkLastEdit")
                End If
            End With


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Sub moveDataRowToProperties _
            (ByVal tempRow As DataRow, _
             ByRef tempDC As dc_Link)

        Try
            tempDC.initProperties()
            With tempRow
                tempDC.LinkKey = .Item("linkKey")

                If Not (IsDBNull(.Item("linkCableLabel"))) Then
                    tempDC.linkCableLabel = .Item("linkCableLabel")
                End If

                tempDC.linkPortAKey = tempRow.Item("linkPortAKey")
                tempDC.linkPortBKey = tempRow.Item("linkPortBKey")

                If Not (IsDBNull(tempRow.Item("linkType"))) Then
                    tempDC.linkType = tempRow.Item("linkType")
                End If

                tempDC.linkMediaLength = tempRow.Item("linkMediaLength")
                If Not (IsDBNull(.Item("linktxtSpatial"))) Then
                    tempDC.linktxtSpatial = .Item("linktxtSpatial")
                Else
                    tempDC.linktxtSpatial = ""
                End If
                If Not (IsDBNull(.Item("linkSpatial"))) Then
                    tempDC.linkSpatial = .Item("linkSpatial")
                Else
                    tempDC.linkSpatial = Nothing
                End If
                tempDC.linkSpeed = tempRow.Item("linkSpeed")
                tempDC.linkLatency = tempRow.Item("linkLatency")
                tempDC.linkPLState = tempRow.Item("linkPLState")

                If Not (IsDBNull(tempRow.Item("linkComments"))) Then
                    tempDC.linkComments = tempRow.Item("linkComments")
                End If

                If Not (IsDBNull(tempRow.Item("linkLastUpdate"))) Then
                    tempDC.linkLastUpdate = tempRow.Item("linkLastUpdate")
                End If
                If Not (IsDBNull(tempRow.Item("linklastedit"))) Then
                    tempDC.linkLastEdit = tempRow.Item("linkLastEdit")
                End If
            End With


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Sub moveDataTableToObservableCollection _
            (ByVal dtTemp As DataTable)

        Try

            If 0 < dtTemp.Rows.Count Then

                If m_oc IsNot Nothing Then
                    m_oc = Nothing
                    m_oc = New Collection(Of dc_Link)
                Else
                    m_oc = New Collection(Of dc_Link)
                End If

                Dim drTemp As DataRow
                Dim dcTemp As dc_Link
                For Each drTemp In dtTemp.Rows
                    dcTemp = New dc_Link
                    moveDataRowToProperties(drTemp, dcTemp)
                    m_oc.Add(dcTemp)
                Next

            End If

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Public Function moveDataTableToXML() As XmlDocument

        Dim writer = New System.IO.StringWriter
        Dim m_dt_xml As Xml.XmlDocument = Nothing

        Try


            m_dt.WriteXml(writer, XmlWriteMode.WriteSchema, True)
            m_dt_xml = Nothing
            m_dt_xml = New Xml.XmlDocument
            m_dt_xml.LoadXml(writer.ToString)

        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally

            writer = Nothing

        End Try

        Return m_dt_xml


    End Function


#End Region

#Region " database calls "

    '
    '
    '
    Public Sub dbSelectNetworkLinkExists()

        Dim portA As dc_Port = Nothing
        Dim portB As dc_Port = Nothing
        Dim clsPort As clsAttrPortData = New clsAttrPortData(drawingApplication, drawingDocument)


        Try

            clsPort.dbSelectAttrPortDataByPortKey(m_dc.linkPortAKey)
            portA = clsPort.m_dc
            clsPort.dbSelectAttrPortDataByPortKey(m_dc.linkPortBKey)
            portB = clsPort.m_dc

            initDataSetAndTable()

            Dim cmd As DbCommand
            cmd = m_db.GetStoredProcCommand("selectNetworkLinkExists")
            m_db.AddInParameter(cmd, "@nodeA", DbType.Int32, portA.portCompKey)
            m_db.AddInParameter(cmd, "@portA", DbType.String, portA.portName)
            m_db.AddInParameter(cmd, "@nodeB", DbType.Int32, portB.portCompKey)
            m_db.AddInParameter(cmd, "@portB", DbType.String, portB.portName)

            m_db.LoadDataSet(cmd, m_ds, dc_racktables.tblNetworkLink.tostring)



        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
            portA = Nothing
            portB = Nothing
            clsPort = Nothing
        End Try


    End Sub

    '
    '
    '
    Public Sub dbSelectAllNetworkLinks()


        Try

            If m_dc Is Nothing Then
                m_dc = New dc_Link
            Else
                m_dc = Nothing
                m_dc = New dc_Link
            End If

            initDataSetAndTable()

            ' Retrieve the initial data
            Dim cmd As DbCommand = m_db.GetStoredProcCommand(readAll)
            m_db.LoadDataSet(cmd, m_ds, dc_racktables.tblNetworkLink.tostring)
            m_dt = m_ds.Tables(dc_racktables.tblNetworkLink.tostring)



        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    ' pass in a rackkey and return a table of network links
    '
    Public Sub dbSelectNetworkLinksByRackKey _
                (ByVal lngRackKey As Int32)

        Try

            initTempDataSetAndTable()

            Dim cmd As DbCommand
            cmd = m_db.GetStoredProcCommand("selectNetworkLinksByRack")
            m_db.AddInParameter(cmd, "@rackKey", DbType.Int32, lngRackKey)
            m_db.LoadDataSet(cmd, m_tempds, "temp")
            m_tempdt = m_tempds.Tables("temp")

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Finally
        End Try



    End Sub

    '
    ' pass in a rowkey and return a table of network links
    '
    Public Sub dbSelectNetworkLinksByRowKey _
                (ByVal lngRowKey As Int32)
        Try

            initTempDataSetAndTable()

            Dim cmd As DbCommand
            cmd = m_db.GetStoredProcCommand("selectNetworkLinksByRow")
            m_db.AddInParameter(cmd, "@RowKey", DbType.Int32, lngRowKey)
            m_db.LoadDataSet(cmd, m_tempds, "temp")
            m_tempdt = m_tempds.Tables("temp")

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If

        Finally
        End Try



    End Sub

    '
    '
    '
    Public Function dbSelectNetworkLinkByLinkKey _
            (ByVal intLinkKey As Int32) _
            As System.Data.DataTable


        Dim dtTemp As DataTable = New DataTable
        Dim dsTemp As DataSet = New DataSet

        Try


            Dim cmd As DbCommand
            cmd = m_db.GetStoredProcCommand("selectNetworkLinkByLinkKey")
            m_db.AddInParameter(cmd, "@LinkKey", DbType.Int32, intLinkKey)
            m_db.LoadDataSet(cmd, dsTemp, "linkData")

            dtTemp = dsTemp.Tables("linkData").Copy

            If dtTemp.Rows.Count = 1 Then
                Dim m_dr As System.Data.DataRow = dtTemp.Rows(0)
                moveDataRowToProperties(m_dr)
            End If

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If

        Finally
        End Try

        Return dtTemp

    End Function

    '
    ' we use this one to chase a link key list, usually stored in an edge record
    '
    Public Function dbBuildLinksByLinkKeyCollection(ByVal colLinks As Collection) _
        As System.Data.DataTable

        Dim dtTemp As DataTable = New DataTable
        Dim dtTempIn As DataTable = New DataTable
        Dim drTemp As DataRow
        Dim intLinkKey As Int32


        Try


            ' use the collection of rack keys to create a table of network links
            For intCt = 1 To colLinks.Count
                If dtTempIn Is Nothing Then
                    dtTempIn = New DataTable
                Else
                    dtTempIn = Nothing
                    dtTempIn = New DataTable
                End If
                intLinkKey = colLinks.Item(intCt)
                dtTempIn = dbSelectNetworkLinkByLinkKey(intLinkKey)
                If intCt = 1 Then
                    dtTemp = dtTempIn.Copy
                Else
                    For Each drTemp In dtTempIn.Rows
                        With drTemp
                            dtTemp.ImportRow(drTemp)
                        End With
                    Next
                End If
            Next intCt ' lngrack key

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        Return dtTemp

    End Function

    '
    ' this builds a table of links that have completed connections in the urri collection
    ' so that they can be drawn in the visio drawing, both sides must complete in the selected
    ' racks (i.e. no hanging cables)
    '
    Public Sub dbBuildLinksByURRICollection _
            (ByVal colURRIKeys As Collection(Of clsDC_RackData.rackURRI))

        Dim drTemp As DataRow
        Dim dtOutput As DataTable = Nothing
        Dim intRackCompKey As Int32
        Dim dictRacks As Dictionary(Of Int32, Int32) = New Dictionary(Of Int32, Int32)
        Dim dictLinksFound As Dictionary(Of Int32, Int32) = New Dictionary(Of Int32, Int32)

        Dim rckURRI As clsDC_RackData.rackURRI


        Try
            Dim strTableName As String = DC_RackTables.tblNetworkLink.ToString

            initTempDataSetAndTable()

            ' parse out the rack component keys to a dictionary
            Dim intKey As Int32 = 1
            For Each rckURRI In colURRIKeys
                If -1 < rckURRI.rckKey Then
                    dictRacks.Add(intKey, rckURRI.rckKey)
                    intKey = intKey + 1
                End If
            Next rckURRI

            Dim intCt As Integer
            Dim blnFound As Boolean = False
            Dim lngRackA As Int32
            Dim lngRackB As Int32
            Dim intLinkKey As Int32
            Dim intLink As Integer = 1

            ' use the collection of rack keys to create a table of network links
            For intCt = 1 To dictRacks.Count
                intRackCompKey = dictRacks.Item(intCt)
                ' go get a list of links
                dbSelectNetworkLinksByRackKey(intRackCompKey)
                ' for the first rack copy the data to the temp table
                If intCt = 1 Then
                    dtOutput = Nothing
                    dtOutput = New DataTable
                    dtOutput = m_tempdt.Copy
                    dtOutput.Clear()
                Else
                End If
                For Each drTemp In m_tempdt.Rows
                    With drTemp
                        ' first make sure both racks are going to be in the drawing
                        lngRackA = .Item("vwlocRackACompKey")
                        lngRackB = .Item("vwlocRackBCompKey")
                        intLinkKey = .Item("linkKey")
                        If dictRacks.ContainsValue(lngRackA) = True _
                            And dictRacks.ContainsValue(lngRackB) = True Then
                            ' then test to see if we already have it
                            If dictLinksFound.ContainsValue(intLinkKey) = False Then
                                dictLinksFound.Add(intLink, intLinkKey)
                                intLink = intLink + 1
                                dtOutput.ImportRow(drTemp)
                            End If ' test for link already captured
                        End If ' test to make sure links are in drawing
                    End With
                Next
            Next intCt ' lngrack key

            ' now move the work table to the public data defintions
            initDataSetAndTable()

            dtOutput.TableName = strTableName
            m_dt = dtOutput.Copy
            If Not (m_ds.Tables(strTableName) Is Nothing) Then
                m_ds.Tables(strTableName).Clear()
                For Each drTemp In dtOutput.Rows
                    m_ds.Tables(strTableName).ImportRow(drTemp)
                Next
            Else
                m_ds.Tables.Add(dtOutput.Copy)
            End If


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            '********* visio snippet vb.net vis0059vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        dictRacks = Nothing
        dictLinksFound = Nothing

    End Sub

    '
    ' this one doesn't care if they attach into the list or not, they
    ' touch one of the racks that we are interested in
    ' needed in case a row/rack is to be deleted
    '
    Public Sub dbBuildAttachedLinksByURRICollection _
            (ByVal colURRIKeys As Collection(Of clsDC_RackData.rackURRI))

        Dim drTemp As DataRow
        Dim lngRackKey As Int32
        Dim colRacks As Collection = New Collection
        Dim rckURRI As clsDC_RackData.rackURRI


        Try

            initTempDataSetAndTable()

            ' parse out the rack keys to a collection
            For Each rckURRI In colURRIKeys
                If -1 < rckURRI.rckKey Then
                    colRacks.Add(rckURRI.rckKey)
                End If
            Next rckURRI

            Dim intCt As Integer
            Dim blnFound As Boolean = False
            Dim colLinksFound As Collection = New Collection
            Dim intLinkKey As Int32

            ' use the collection of rack keys to create a table of network links
            For intCt = 1 To colRacks.Count
                lngRackKey = colRacks.Item(intCt)
                ' go get a list of links
                dbSelectNetworkLinksByRackKey(lngRackKey)
                For Each drTemp In m_tempdt.Rows
                    With drTemp
                        intLinkKey = drTemp.Item("linkKey")
                        If colLinksFound.Contains(CStr(intLinkKey)) = False Then
                            colLinksFound.Add(intLinkKey, CStr(intLinkKey))
                            m_dt.ImportRow(drTemp)
                        End If ' test for link already captured
                    End With
                Next
            Next intCt ' lngrack key

            For Each drTemp In m_dt.Rows
                m_ds.Tables(DC_RackTables.tblNetworkLink.ToString).ImportRow(drTemp)
            Next drTemp

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    ' uses the stGeomFromText, stPointFromText
    ' longitude/latitude
    '
    Public Sub dbUpdateNetworkLinkGeography _
            (ByVal intLinkKey As Int32, _
            ByVal strWKT As String, _
            ByVal intSRID As Int32)


        Try


            Dim cmd As DbCommand = m_db.GetStoredProcCommand("updateNetworkLinkGeography")
            m_db.AddInParameter(cmd, "@linkKey", DbType.Int32, intLinkKey)
            m_db.AddInParameter(cmd, "@wkt", DbType.String, strWKT)
            m_db.AddInParameter(cmd, "@srid", DbType.Int32, intSRID)

            Dim affectedRows As Int16 = m_db.ExecuteNonQuery(cmd)

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch Ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(Ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub


#End Region

#Region " Standard calls "

    '
    ' clear the general dataset and table, create columns in the table, and move it to
    ' the dataset
    '
    Public Sub initDataSetAndTable()

        Try

            ' make sure the root stuff is there
            If m_ds Is Nothing Then
                m_ds = New DataSet
            Else
                m_ds = Nothing
                m_ds = New DataSet
            End If
            m_ds.SchemaSerializationMode = SchemaSerializationMode.IncludeSchema

            If m_dt Is Nothing Then
                m_dt = New DataTable
            Else
                m_dt = Nothing
                m_dt = New DataTable
            End If

            If m_oc Is Nothing Then
                m_oc = New Collection(Of dc_Link)
            Else
                m_oc = Nothing
                m_oc = New Collection(Of dc_Link)
            End If

            If m_dc Is Nothing Then
                m_dc = New dc_Link(strUserId)
            Else
                m_dc = Nothing
                m_dc = New dc_Link(strUserId)
            End If

            CreateTableColumns(m_dt)
            m_dt.TableName = DC_RackTables.tblNetworkLink.ToString

            m_ds.Tables.Add(m_dt)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try



    End Sub

    '
    '
    '
    Private Sub initTempDataSetAndTable()

        Try

            ' make sure the root stuff is there
            If m_tempds Is Nothing Then
                m_tempds = New DataSet
            Else
                m_tempds = Nothing
                m_tempds = New DataSet
            End If
            m_tempds.SchemaSerializationMode = SchemaSerializationMode.IncludeSchema

            If m_tempdt Is Nothing Then
                m_tempdt = New DataTable
            Else
                m_tempdt = Nothing
                m_tempdt = New DataTable
            End If

            m_tempdt.TableName = "temp"

            m_tempds.Tables.Add(m_tempdt)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try



    End Sub

    '
    '
    '
    Private Sub buildInsertNetworkLinkCommand()
        Try



            m_insertCommand = m_db.GetStoredProcCommand("insertNetworkLink")

            Dim cmdActive As DbCommand
            cmdActive = m_insertCommand

            m_db.AddInParameter(cmdActive, "linkCableLabel", DbType.String, "linkCableLabel", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkPortAKey", DbType.Int32, "linkPortAKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkPortBKey", DbType.Int32, "linkPortBKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkType", DbType.Int16, "linkType", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkMediaLength", DbType.Int32, "linkMediaLength", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkSpeed", DbType.Int16, "linkSpeed", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkLatency", DbType.Double, "linkLatency", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkPLState", DbType.String, "linkPLState", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkComments", DbType.String, "linkComments", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkLastUpdate", DbType.Date, "linkLastUpdate", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkLastEdit", DbType.String, "linkLastEdit", DataRowVersion.Current)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try
    End Sub

    '
    '
    '
    Private Sub buildUpdateNetworkLinkCommand()




        Try
            m_updateCommand = m_db.GetStoredProcCommand("updateNetworkLink")

            Dim cmdActive As DbCommand
            cmdActive = m_updateCommand

            m_db.AddInParameter(cmdActive, "linkKey", DbType.Int32, "linkKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkCableLabel", DbType.String, "linkCableLabel", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkPortAKey", DbType.Int32, "linkPortAKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkPortBKey", DbType.Int32, "linkPortBKey", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkType", DbType.Int16, "linkType", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkMediaLength", DbType.Int32, "linkMediaLength", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkSpeed", DbType.Int16, "linkSpeed", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkLatency", DbType.Double, "linkLatency", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkPLState", DbType.String, "linkPLState", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkComments", DbType.String, "linkComments", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkLastUpdate", DbType.Date, "linkLastUpdate", DataRowVersion.Current)
            m_db.AddInParameter(cmdActive, "linkLastEdit", DbType.String, "linkLastEdit", DataRowVersion.Current)



        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    '
    '
    '
    Private Sub buildDeleteNetworkLinkCommand()
        Try


            m_deleteCommand = m_db.GetStoredProcCommand("deleteNetworkLink")

            Dim cmdActive As DbCommand
            cmdActive = m_deleteCommand

            '	@linkKey int,
            m_db.AddInParameter(cmdActive, "linkKey", DbType.Int32, "linkKey", DataRowVersion.Current)


        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        End Try
    End Sub

    '
    '
    '
    Public Function dbUpdateDataSet() As Int16

        Dim rowsAffected As Int16 = 0

        Try

            rowsAffected = m_db.UpdateDataSet(m_ds, DC_RackTables.tblNetworkLink.ToString, _
                                        m_insertCommand, _
                                        m_updateCommand, _
                                        m_deleteCommand, _
                                        UpdateBehavior.Standard)
            'msgbox rowsAffected

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If

        End Try

        Return rowsAffected

    End Function


    '
    ' create a record based on property values move it to the generic datatable
    ' then copy the table to the database
    '
    Public Function addNetworkLinkDataSourceRecord _
            (ByVal tempDC As dc_Link, _
             Optional ByVal blnSilent As Boolean = False) _
             As Integer

        Dim intRowsAffected As Integer = 0

        Try

            initDataSetAndTable()

            Dim m_dr As DataRow = m_ds.Tables(DC_RackTables.tblNetworkLink.ToString).NewRow
            movePropertiesToDataRow(m_dr, tempDC)
            m_ds.Tables(DC_RackTables.tblNetworkLink.ToString).Rows.Add(m_dr)
            intRowsAffected = dbUpdateDataSet()

            If blnSilent = False Then
                MsgBox("DataRowsUpated = " & intRowsAffected)
            End If

        Catch sql As SqlException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

        Return intRowsAffected

    End Function


#End Region

#Region " Visio Interaction "

    '
    ' 
    '
    Public Sub UpdateNetworkLinkProperties _
        (ByRef visShape As Microsoft.Office.Interop.Visio.Shape, _
         Optional ByVal drTemp As System.Data.DataRow = Nothing)

        Dim visCell As Microsoft.Office.Interop.Visio.Cell

        If drTemp IsNot Nothing Then
            moveDataRowToProperties(drTemp)
        End If

        Try



            ' this sets the connector style to straight (IMHO looks better on v2010)
            visShape.CellsSRC(VisSectionIndices.visSectionObject, VisRowIndices.visRowShapeLayout, VisCellIndices.visSLOLineRouteExt).FormulaU = "1"
            visShape.CellsSRC(VisSectionIndices.visSectionObject, VisRowIndices.visRowShapeLayout, VisCellIndices.visSLORouteStyle).FormulaU = "16"

            ' we have to guard the line color so that data graphics will not
            ' change it

            visCell = visShape.CellsSRC(VisSectionIndices.visSectionObject, VisRowIndices.visRowLock, VisCellIndices.visLockThemeEffects)
            visCell.Formula = True
            visCell = visShape.CellsSRC(VisSectionIndices.visSectionObject, VisRowIndices.visRowLock, VisCellIndices.visLockThemeColors)
            visCell.Formula = True
            visCell = visShape.CellsSRC(VisSectionIndices.visSectionObject, VisRowIndices.visRowLock, VisCellIndices.visLockFormat)
            visCell.Formula = True
            visCell = visShape.CellsSRC(VisSectionIndices.visSectionObject, VisRowIndices.visRowLock, VisCellIndices.visLockFromGroupFormat)
            visCell.Formula = True

            ' need to add a custom property for shape name so that data graphics can access it
            ' this is not mirrored to the database
            _clsVisio.ForceShapeData(visShape, "linkCableName", visShape.Name, "attrNetworkLink")

            Dim strVisColor As String = ""
            Dim intVisColor As Integer = 0
            Select Case m_dc.linkType
                ' first the lan wiring
                ' for fiber a red
                Case m_dc.enumLinkTypes.linkFiber
                    intVisColor = m_dc.enumLinkColors.linkFiber
                    ' for copper use blue
                Case m_dc.enumLinkTypes.linkCopper
                    intVisColor = m_dc.enumLinkColors.linkCopper
                Case m_dc.enumLinkTypes.linkSerial
                    intVisColor = m_dc.enumLinkColors.linkSerial
                Case m_dc.enumLinkTypes.linkUSB
                    intVisColor = m_dc.enumLinkColors.linkUSB
                    ' then the wan stuff
                Case m_dc.enumLinkTypes.linkInternet
                    intVisColor = m_dc.enumLinkColors.linkOther
                    ' finally the default
                Case Else
                    intVisColor = m_dc.enumLinkColors.linkOther
            End Select

            visCell = visShape.Cells("LineColor")
            visCell.FormulaU = "Guard(" & intVisColor & ")"

            With m_dc
                _clsVisio.ForceShapeData(visShape, "linkType", .getLinkType(.linkType), "attrNetworkLink")
                _clsVisio.ForceShapeData(visShape, "linkKey", .LinkKey, "attrNetworkLink")
                _clsVisio.ForceShapeData(visShape, "linkCableLabel", .linkCableLabel, "attrNetworkLink")
                _clsVisio.ForceShapeData(visShape, "linkMediaLength", .linkMediaLength, "attrNetworkLink")
                ' make sure the length is in feet, not inches
                If visShape.CellExists("prop.linkMediaLength", False) = True Then
                    visCell = visShape.Cells("prop.linkMediaLength")
                    visCell.FormulaU = visShape.LengthIU / 12
                End If

                _clsVisio.ForceShapeData(visShape, "linkSpeed", .linkSpeed, "attrNetworkLink")
                _clsVisio.ForceShapeData(visShape, "linkLatency", .linkLatency, "attrNetworkLink")
                _clsVisio.ForceShapeData(visShape, "linkPLState", .getLinkState(.linkType), "attrNetworkLink")
                _clsVisio.ForceShapeData(visShape, "linkComments", .linkComments, "attrNetworkLink")
            End With

            ' add the ability to turn the shape on and off
            _clsVisio.AddUserPropertyToShape( _
                    visShape, _
                    "HideLinkShape", _
                    "HideLinkShape", _
                    "HideLinkShape", _
                    "False", Nothing)

            ' add the user flag to the hidelink cell
            If visShape.CellsSRCExists(VisSectionIndices.visSectionFirstComponent, VisRowIndices.visRowComponent, VisCellIndices.visCompNoShow, False) = True Then
                visCell = visShape.CellsSRC(VisSectionIndices.visSectionFirstComponent, VisRowIndices.visRowComponent, VisCellIndices.visCompNoShow)
                visCell.FormulaU = "user.HideLinkShape"
            End If

            visCell = visShape.Cells("LineWeight")
            visCell.Formula = "0.5 pt"
            visCell = visShape.Cells("BeginArrow")
            visCell.Formula = "20"
            visCell = visShape.Cells("EndArrow")
            visCell.Formula = "20"
            visCell = visShape.Cells("BeginArrowSize")
            visCell.Formula = VisCellVals.visArrowSizeVerySmall
            visCell = visShape.Cells("EndArrowSize")
            visCell.Formula = VisCellVals.visArrowSizeVerySmall


        Catch com As COMException
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
            MsgBox("Add Network Link Attributes " & ex.Message & " " & visShape.Name)
        End Try


    End Sub

#End Region

#Region " constructor "

    '
    '
    '
    Public Sub New(ByVal visApp As Microsoft.Office.Interop.Visio.Application, _
                   ByVal visDoc As Microsoft.Office.Interop.Visio.Document)

        Try

            m_db = DatabaseFactory.CreateDatabase()


            strUserId = Environment.UserDomainName & "/" & Environment.UserName

            '
            ' init an object class so that the default constants are available
            ' to the table definitions
            '
            If m_dc Is Nothing Then
                m_dc = New dc_Link(strUserId)
            Else
                m_dc = Nothing
                m_dc = New dc_Link(strUserId)
            End If


            drawingApplication = visApp
            drawingDocument = visDoc
            drawingPage = visApp.ActivePage


            _clsVisio = New visRackLocations.clsVisioSupport
            _clsVisio.drawingApplication = visApp
            _clsVisio.drawingDocument = visDoc

            m_updateCommand = Nothing
            m_insertCommand = Nothing
            m_deleteCommand = Nothing

            buildDeleteNetworkLinkCommand()
            buildInsertNetworkLinkCommand()
            buildUpdateNetworkLinkCommand()


        Catch ex As Exception
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If
        End Try

    End Sub

    ' definitions for the containers
    Private Const constlinkPinX As String = "1.5 in"
    Private Const constlinkPinY As String = "9.875 in"

    Private Const constlinkHeader As String = "NetworkLink"
    Private Const constlinkMaster As String = "Container 4"


    '
    ' based on the link key, read the link record from the data source
    '
    Public Function buildLinkContainer _
                        (ByVal intLinkKey As Int32, _
                       ByVal _clsData As clsDC_RackData) _
                        As Microsoft.Office.Interop.Visio.Shape

        Dim shpContainer As Microsoft.Office.Interop.Visio.Shape = Nothing

        Try

            _clsVisio.drawingPage = drawingPage
            drawingDocument = drawingPage.Document

            initDataSetAndTable()

            m_dt = dbSelectNetworkLinkByLinkKey(intLinkKey).Copy
            m_dt.TableName = DC_RackTables.tblNetworkLink.ToString

            Dim drTemp As System.Data.DataRow = Nothing
            Dim strTable As String = DC_RackTables.tblNetworkLink.ToString
            If Not (m_ds.Tables(strTable) Is Nothing) Then
                m_ds.Tables(strTable).Clear()
                For Each drTemp In m_dt.Rows
                    m_ds.Tables(strTable).ImportRow(drTemp)
                Next
            Else
                m_ds.Tables.Add(m_dt.Copy)
            End If

            Dim colInput As Collection = New Collection
            Dim linkQuery = From link In m_ds.Tables(strTable).AsEnumerable() _
                       Where link!linkkey = intLinkKey
                      Select link

            ' we should only have transferred in a single link key
            If linkQuery.Count = 1 Then
                For Each l In linkQuery
                    colInput.Add("linkKey_" & l.Item("linkKey").ToString)
                    drTemp = l
                    m_dc.initProperties()
                    moveDataRowToProperties(drTemp)
                Next l
            End If

            ' create a list control
            Dim listControl As Microsoft.Office.Interop.Visio.Shape = Nothing


            ' pass in the created collection and return a populated list control
            Dim colMembers As Collection = New Collection


            ' get the datagraphic
            Dim strStencil As String = ""
            Dim strMaster As String = ""
            Dim strDGMaster As String = ""
            Dim visDG As Microsoft.Office.Interop.Visio.Master = Nothing
            Dim intLabelFont As Integer
            Dim intValueFont As Integer
            Dim dblCalloutWidth As Double
            Dim dgmasterQuery = From datagraphic In _clsData.m_ds.Tables(DC_RackTables.tblDGMasters.ToString).AsEnumerable() _
                                Where datagraphic!dgmTable = DC_RackTables.tblNetworkLink.ToString _
                                Select datagraphic

            ' should only be one..
            For Each m In dgmasterQuery
                If LCase(m!dgmTable) = LCase(DC_RackTables.tblNetworkLink.ToString) Then
                    strStencil = m!dgmSurrogateStencil
                    strStencil = _CustomStencilPath & strStencil
                    strMaster = m!dgmSurrogateMaster
                    intLabelFont = CInt(m!dgmFontLabel)
                    intValueFont = CInt(m!dgmFontValue)
                    dblCalloutWidth = CDbl(m!dgmCalloutWidth)
                    strDGMaster = m!dgmMaster
                    Exit For
                End If
            Next

            ' pass in the created collection and return a populated list control
            colMembers = _clsVisio.dropDropDownBoxItems(colInput, strMaster, strStencil, "1.5 in", "1 in", vbTrue)

            Dim visShape As Microsoft.Office.Interop.Visio.Shape = Nothing
            Dim visCell As Microsoft.Office.Interop.Visio.Cell = Nothing

            ' should only be one
            For Each shapeid In colMembers

                visShape = drawingPage.Shapes.ItemFromID(shapeid)

                ' clear any shape data properties
                _clsVisio.deleteShapeData(visShape)

                ' set it semi-transparent
                Dim strTrans As String = "50%"
                ' first the fill properties
                _clsVisio.recurseApplyCellFormula(visShape, VisSectionIndices.visSectionObject, VisRowIndices.visRowFill, VisCellIndices.visFillForegndTrans, strTrans)
                _clsVisio.recurseApplyCellFormula(visShape, VisSectionIndices.visSectionObject, VisRowIndices.visRowFill, VisCellIndices.visFillBkgndTrans, strTrans)
                ' then the line properties
                _clsVisio.recurseApplyCellFormula(visShape, VisSectionIndices.visSectionObject, VisRowIndices.visRowLine, VisCellIndices.visLineColorTrans, strTrans)
                ' prep it for applying the datagraphics by applying the data from the dgmasters table
                _clsVisio.addDataGraphicUserFieldsToShape _
                        (visShape, _
                        intValueFont.ToString, _
                        intLabelFont.ToString, _
                        dblCalloutWidth.ToString)

                'Check that the requested Data Graphic Master exits
                For Each visMaster In drawingDocument.Masters
                    If visMaster.Type = VisMasterTypes.visTypeDataGraphic Then
                        If visMaster.Name = strDGMaster Then
                            visDG = visMaster
                            Exit For
                        End If
                    End If
                Next

                UpdateNetworkLinkProperties(visShape, drTemp)

                ' the linkcablename is a pretty long field, so we will not put it in for cables
                'visShape.Text = drTemp.Field(Of String)("linkCableName")

                ' move the cable shape name to comment field so we get mouse over
                If visShape.CellsSRCExists(VisSectionIndices.visSectionObject, VisRowIndices.visRowMisc, VisCellIndices.visComment, False) = True Then
                    visCell = visShape.CellsSRC(VisSectionIndices.visSectionObject, VisRowIndices.visRowMisc, VisCellIndices.visComment)
                    _clsVisio.SetCellValueToString(visCell, visShape.NameU)
                End If


                ' allow the legend to keep track of the shapes
                _clsVisio.ForceUserProperty(visShape, "visLegendShape", "2.0")

                'Apply the Data Graphic to the Shape
                visShape.DataGraphic = visDG

                ' unlock the groups so we can change the font sizes
                _clsVisio.recurseApplyCellFormula(visShape, VisSectionIndices.visSectionObject, VisRowIndices.visRowLock, VisCellIndices.visLockGroup, "0")

                If visShape.CellExists("user.dbIntLabelFont", False) = True Then

                    ' get the loaded values 
                    intLabelFont = CInt(visShape.Cells("user.dbintlabelfont").ResultIU)
                    intValueFont = CInt(visShape.Cells("user.dbintvaluefont").ResultIU)
                    dblCalloutWidth = CDbl(visShape.Cells("user.dbdblcallout").ResultIU)

                    ' set the callout width = 85% of the surrogate shapes width (as a formula) so that it fits inside the shape
                    Dim strId As String = visShape.NameID & "!Width*.85"
                    strId = "Guard(" & strId & ")"

                    _clsVisio.recurseApplyCustomFormula(visShape, "prop.msvcalloutproplabelsize", intLabelFont.ToString & " pt")
                    _clsVisio.recurseApplyCustomFormula(visShape, "prop.msvcalloutpropvaluesize", intValueFont.ToString & " pt")
                    _clsVisio.recurseApplyCustomFormula(visShape, "prop.msvcalloutpropwidth", strId)

                End If

            Next shapeid

            listControl = _clsVisio.loadListControl(colMembers, VisListAlignment.visListAlignCenterOrMiddle, VisListDirection.visListDirLeftToRight)
            'listControl.Name = "listLinks"
            'listControl.NameU = "listLinks"

            shpContainer = _clsVisio.addContainerToPage(constlinkMaster, "contLinkData", "LinkData")

            ' add the list control to the container
            _clsVisio.AddShapeToContainer(shpContainer, listControl)

            shpContainer.Cells("pinx").Formula = constlinkPinX
            shpContainer.Cells("piny").Formula = constlinkPinY



        Catch com As COMException
            '********* visio snippet vb.net vis0056vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(com, "Com+ Policy")
            If (rethrow) Then
                Throw
            End If
        Catch sql As SqlException
            '********* visio snippet vb.net vis0057vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(sql, "Database Policy")
            If (rethrow) Then
                Throw
            End If
        Catch ex As Exception
            '********* visio snippet vb.net vis0059vb ******************
            Dim rethrow As Boolean = ExceptionPolicy.HandleException(ex, "Log Only Policy")
            If (rethrow) Then
                Throw
            End If

        End Try

        Return shpContainer

    End Function




#End Region




End Class
